<?php

namespace App\Model\Backend;

use Illuminate\Database\Eloquent\Model;

class TemplatesStagesTaskModel extends Model
{
    protected $table = 'template_stages_task';
    protected $primaryKey = 'task_id';
    public function taskInfo($tid){
        $arr=array();
        $taskInfo=$this->where(['tid'=>$tid])->orderBy('level','ASC')->orderBy('task_id','ASC')->get();
        $member=new Member();
        $role=new RoleModel();
        foreach($taskInfo as $k=>$v){
            $name1=array();
            $name2=array();
            $arr[$k]['id']=$v['task_id'];
            $arr[$k]['name']=$v['task_name'];
            $arr[$k]['level']=$v['level'];
            $arr[$k]['stage_id']=$v['sid'];
            $arr[$k]['audit_rank']=$v['audit_rank'];
            $arr[$k]['type_id']=$v['type_id'];
            $arr[$k]['role_id']=$v['role_id'];
			$arr[$k]['money'] = $v['money'];
            $roles1=$role->where(['rid'=>$v['type_id']])->get();

            $roles2=$role->where(['rid'=>$v['role_id']])->get();
            foreach($roles1 as $i=>$y){
                $userInfo1=$member->find($y['uid']);
                $name1[$i]['name']=$userInfo1['username'];
                $name1[$i]['uid']=$y['uid'];
            }

            foreach($roles2 as $item=>$value){
                $userInfo2=$member->find($value['uid']);
                $name2[$item]['name']=$userInfo2['username'];
                $name2[$item]['uid']=$value['uid'];
            }

            $arr[$k]['member_id_task']=$name1;
            $arr[$k]['member_id_check']=$name2;
        }
        return $arr;
    }
}
